import java.math.BigInteger;
import java.util.*;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
public class test {
	public static void main(String[] args){
//		Scanner scan=new Scanner(System.in);
//		System.out.println("Username");
//		String username=scan.nextLine();
//		System.out.println("Password");
//		String password=scan.nextLine();
//		//User: Ronald, pass Brown
//		//Authentication.addUser(username, password);
//		System.out.println(Authentication.verify(username, password));
		
		try {
			
			DiffieHellman dha= new DiffieHellman();
			DiffieHellman dhb= new DiffieHellman();
			
			//Alice is client
			//Bob is server
			
			//Generated on Client
			int ak = (int)Math.random()*50;
			//This will be static on server
			int bk = 32;
			//Client generated PG
			BigInteger[] pg = dha.GeneratePG();
			//Client getnerates Public Key (apub) using it's p = pg[0] g = pg[1]
			byte[] apub = dha.CreateSendInteger(pg[0], pg[1], ak);
			//CLient sends pg[] to server and apub to server
			
			//Server generates public key for itself using pg[] passed in
			byte[] bpub = dhb.CreateSendInteger(pg[0], pg[1], bk);
			
			//Client gets the key using createFullKey on server's public key (bpuh)
			SecretKey Ka = dha.CreateFullKey(bpub);
			//Same thing for server using clients public key
			SecretKey Kb = dhb.CreateFullKey(apub);
			
			//Test
			
			//System.out.write(apub);
			//System.out.println(Ka.toString() + " : " + Kb.toString());
			
		    // Generate a temporary key. In practice, you would save this key.
		    // See also Encrypting with DES Using a Pass Phrase.
//		    SecretKey key = KeyGenerator.getInstance("AES").generateKey();

		    // Create encrypter/decrypter class
			//Create one for client and server initilized using the key
		    Encryption Aencrypter = new Encryption(Ka);
		    Encryption Bencrypter = new Encryption(Kb);
		    
		    System.out.println("encrypters created");
		    // Encrypt
		    String encrypted = Aencrypter.encrypt("Aditya");
		    System.out.println("encrypted");
		    // Decrypt
		    String decrypted = Bencrypter.decrypt(encrypted);
		    System.out.println("decrypted");
		    
		    System.out.println(encrypted);
		    System.out.println(decrypted);
		} catch (Exception e) {
		}
		
	}
}
